package com.jinzhi.common.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.domain.Tree;
import com.jinzhi.common.service.DictService;
import com.jinzhi.common.utils.QrCodeUtil;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.NewTrainingCertificatesDO;
import com.jinzhi.jzweb.service.NewTrainingCertificatesService;
import com.jinzhi.oss.service.OssService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * <pre>
 * 数据字典
 * </pre>
 * 
 * <small> 2018年3月23日 | Aron</small>
 */
@Controller
@RequestMapping("/common/erCodeFactory")
public class erCodeFactoryController extends BaseController {
    @Autowired
    private OssService ossService;

    @Autowired
    private NewTrainingCertificatesService newTrainingCertificatesService;
    
    @GetMapping()
    @RequiresPermissions("common:erCodeFactory")
    public String sysDict() {
        return "common/erCodeFactory/erCodeFactory";
    }

    @PostMapping("/create")
    @ResponseBody
    public Result<String> create(String value) throws IOException {
        QrCodeUtil.createQrCode(value,"D:/upload/","二维码.jpg");
        return success();
    }

    @PostMapping("/createLogo")
    @ResponseBody
    public Result<String> createLogo(String value) throws IOException {
        String logo="D://upload/logo.jpg";
        QrCodeUtil.createQrCodeLogo(value,"D:/upload/","二维码.jpg",logo);
        return success();
    }

    @GetMapping("/openErCode")
    public String openErCode(Model model){
        model.addAttribute("erCode", "D:/upload/二维码.jpg");
        return "common/erCodeFactory/openErCode";
    }

    @GetMapping("/getQRId")
    public String getQRId(String id,Model model) throws UnsupportedEncodingException {
        System.out.println("进入二维码方法.....................");

        EntityWrapper wrapper =new EntityWrapper();
        wrapper.eq("id_number",id);
        NewTrainingCertificatesDO newTrainingCertificatesDO = newTrainingCertificatesService.selectOne(wrapper);
        model.addAttribute("newTrainingCertificatesDO",newTrainingCertificatesDO);

        return "common/erCodeFactory/selectcate2";
    }

    @GetMapping("/getQRIds")
    public String getQRIds(String id,Model model) throws UnsupportedEncodingException {
        System.out.println("进入二维码方法.....................");

        EntityWrapper wrapper =new EntityWrapper();
        wrapper.eq("numbers",id);
        NewTrainingCertificatesDO newTrainingCertificatesDO = newTrainingCertificatesService.selectOne(wrapper);
        model.addAttribute("newTrainingCertificatesDO",newTrainingCertificatesDO);

        return "common/erCodeFactory/selectcate2";
    }
}
